// pages/login/login.js
var App = getApp();
Page({
  data: {
    userName: 'admin',
    userPassword: 'admin',
    userInfo: ''
  },
  //获取用户输入的用户名
  userNameInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  userPasswordInput: function (e) {
    this.setData({
      userPassword: e.detail.value
    })
  },
  // 登录 
  loginBtnClick: function () {
    console.log("用户名：" + this.data.userName + " 密码：" + this.data.userPassword);
    var userName = this.data.userName;
    var userPassword = this.data.userPassword;
    if (userName == '') {
      wx.showToast({
        title: '请输入用户名',
        icon: 'loading',
        duration: 600
      })
    } else if (userPassword == '') {
      wx.showToast({
        title: '请输入密码',
        icon: 'loading',
        duration: 600
      })
    } else {
      wx.request({
        url: 'http://localhost/pgUsers/login',
        method: 'POST',
        data: {
          userName: userName,
          userPassword: userPassword,

        },
        success: function (data) {
          console.log(data.data)
          wx.showToast({
            title: data.data.msg,
            icon: 'success',
            duration: 1000
          })
          wx.reLaunch({
            url: '/pages/index/index',
          })
        },
        error: function (data) {
          console.log(data)
        }
      })

      // wx.showToast({
      //   title: '登录成功',
      //   icon: 'success',
      //   duration: 1000
      // })

      // wx.navigateTo({
      //   url: '../../pages/index/index',
      // })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log(App);
    //获取全局变量
    this.setData({
      userInfo: App.globalData.userInfo
    });
  }

})